home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 20 December 1999
- //
- // Description:
- // This script implements the "Search for a Command" window.
- //
- // The window is accessed from the Hotkey Editor window and its
- // main purpose is to allow users a simple searching of the commands
- // available for attaching to hotkeys.
- //
-
- /*
- //
- // These are the local and global procedures defined in this file. As well
- // as the unique names of the UI objects created.
- //
- // ----------------------------------------------------------------------
- //
- spacing(string $str, string $longest)
-
- searchForRunTimeCommandWindowSearch()
- searchForRunTimeCommandWindowPrintHelp()
- searchForRunTimeCommandWindowClose()
- searchForRunTimeCommandWindow()
-
- SearchForRunTimeCommandWindow
- SearchForRunTimeCommandWindowSearchFieldGrp
- SearchForRunTimeCommandWindowSearchResultField
- */
-
- proc string spacing(string $str, string $longest)
- //
- // Description:
- // Return a string containing the number of spaces required to
- // make the passed in string argument the same length as the
- // passed in "longest" string.
- //
- // Example:
- //
- // if $str is "Hello"
- // and $longest is "A longer string"
- //
- // then the return string will be " ".
- //
- {
- string $result = "";
- string $spaces = " ";
-
- $numberOfSpacesNeeded = size($longest) - size($str);
-
- if (0 < $numberOfSpacesNeeded) {
- if ($numberOfSpacesNeeded > size($spaces)) {
- $numberOfSpacesNeeded = size($spaces);
- }
- $result = `substring $spaces 1 $numberOfSpacesNeeded`;
- }
-
- return $result;
- }
-
- global proc searchForRunTimeCommandWindowSearch()
- //
- // Description:
- // This function is called when the user changes the text in the
- // search field.
- //
- {
- string $result = "", $command, $match[];
- string $longestNameMatch, $longestCategoryMatch;
- int $matchIndex = 0, $numberOfMatches;
-
- string $searchFor = `textFieldGrp -query -text
- SearchForRunTimeCommandWindowSearchFieldGrp`;
- string $category, $nameHeader = "Command Name";
- string $categoryHeader = "Category", $commandHeader = "Command";
- string $spaceAfterName = " ", $spaceAfterCategory = " ";
-
- if ("" == $searchFor) {
- //
- // Check for empty search string.
- //
- searchForRunTimeCommandWindowPrintHelp();
-
- } else {
- //
- // Look for matches on the command's name and the actual command.
- //
- string $runTimeCommands[] = `runTimeCommand -query -commandArray`;
- for ($runTimeCommand in $runTimeCommands) {
- $command = `runTimeCommand -query -command $runTimeCommand`;
- if (gmatch($runTimeCommand, $searchFor) ||
- gmatch($command, $searchFor)) {
- $match[$matchIndex++] = $runTimeCommand;
- }
- }
-
- $numberOfMatches = size($match);
-
- if (0 < $numberOfMatches) {
- //
- // Matches found.
- //
-
- // Look for the longest command name and category name so we can
- // line up the results.
- //
- $longestNameMatch = $nameHeader;
- for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
- if (size($match[$matchIndex]) > size($longestNameMatch)) {
- $longestNameMatch = $match[$matchIndex];
- }
- }
- $longestCategoryMatch = $categoryHeader;
- for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
- $category = `runTimeCommand -query -category $match[$matchIndex]`;
- if (size($category) > size($longestCategoryMatch)) {
- $longestCategoryMatch = $category;
- }
- }
-
- // Print out a header for the results.
- //
- $result = $nameHeader + spacing($nameHeader, $longestNameMatch)
- + $spaceAfterName + $categoryHeader
- + spacing($categoryHeader, $longestCategoryMatch)
- + $spaceAfterCategory + $commandHeader + "\n"
- + "-----------------------------------"
- + "-----------------------------------\n";
-
- // For each match print out the command name, category of the
- // command and the actual command.
- //
- for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
- $result += $match[$matchIndex];
-
- $category = `runTimeCommand -query -category $match[$matchIndex]`;
- $result += spacing($match[$matchIndex], $longestNameMatch)
- + $spaceAfterName + $category
- + spacing($category, $longestCategoryMatch)
- + $spaceAfterCategory
- + `runTimeCommand -query -command $match[$matchIndex]` + "\n";
- }
-
- } else {
- //
- // No matches found.
- //
- $result = "No matches found on \"" + $searchFor + "\".\n";
-
- // Does the search string have any *'s in it? If not then
- // suggest that the user should add one.
- //
- if (gmatch($searchFor, "*[**]*")) {
- } else {
- $result += "\nTry adding an asterisk or two, e.g. \"*"
- + $searchFor + "*\".\n";
- }
- }
- scrollField -edit -text $result -insertionPosition 1
- SearchForRunTimeCommandWindowSearchResultField;
- }
- }
-
- global proc searchForRunTimeCommandWindowPrintHelp()
- //
- // Description:
- // Print out a help message for the user. Describe what is
- // expected in the search field and give some examples.
- //
- {
- string $help = "Enter a case sensitive search string in the\n"
- + "field above.\n\n"
- + "Some examples are:\n"
- + " *Scene\n"
- + " Display*\n"
- + " *UI*\n"
- + " *[Mm]enu*\n";
- scrollField -edit -text $help -insertionPosition 1
- SearchForRunTimeCommandWindowSearchResultField;
- textFieldButtonGrp -edit -text "" SearchForRunTimeCommandWindowSearchFieldGrp;
- }
-
- global proc searchForRunTimeCommandWindowClose()
- //
- // Description:
- // This function is called when the user presses the close button.
- //
- {
- // Delete the window.
- //
- deleteUI -window SearchForRunTimeCommandWindow;
- }
-
- global proc searchForRunTimeCommandWindow()
- //
- // Description:
- // Create a window for searching the runTimeCommands.
- //
- {
- // If the window already exists then just show it and return.
- //
- if (`window -exists SearchForRunTimeCommandWindow`) {
- showWindow SearchForRunTimeCommandWindow;
- return;
- }
-
- // Otherwise, build the window.
- //
- window -title "Search for Command"
- -iconName "Find Cmd"
- SearchForRunTimeCommandWindow;
-
- string $form = `formLayout`;
-
- string $description = "Enter case sensitive search string"
- + " (for example, *ndo*)";
-
- string $searchFor = `textFieldButtonGrp -label "Search for"
- -buttonLabel "Help"
- -buttonCommand ("searchForRunTimeCommandWindowPrintHelp")
- -adjustableColumn2 2
- -changeCommand ("searchForRunTimeCommandWindowSearch")
- -annotation $description
- SearchForRunTimeCommandWindowSearchFieldGrp`;
-
- string $results = `scrollField -editable false -height 250
- SearchForRunTimeCommandWindowSearchResultField`;
-
- string $close = `button -label "Close"
- -command ("searchForRunTimeCommandWindowClose")`;
-
- formLayout -edit
- -attachForm $searchFor "top" 5
- -attachForm $searchFor "left" 5
- -attachNone $searchFor "bottom"
- -attachForm $searchFor "right" 5
- -attachControl $results "top" 5 $searchFor
- -attachForm $results "left" 5
- -attachControl $results "bottom" 5 $close
- -attachForm $results "right" 5
- -attachNone $close "top"
- -attachForm $close "left" 5
- -attachForm $close "bottom" 5
- -attachForm $close "right" 5
- $form;
-
- showWindow SearchForRunTimeCommandWindow;
- }
-